package com.example.springbootdemo.autowired;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.EmbeddedValueResolverAware;
import org.springframework.stereotype.Component;
import org.springframework.util.StringValueResolver;
// 使用 实现Aware方法，利用 BeanPostProcessor（后置处理） 机制 ，回调获取指定 spring 底层组件
// 通常命名  xxxAware , 后置处理类 xxxProcessor
@Component
public class MyAware implements EmbeddedValueResolverAware, ApplicationContextAware {

    private ApplicationContext context;

    private StringValueResolver resolver;


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.context = applicationContext;
    }

    @Override
    public void setEmbeddedValueResolver(StringValueResolver resolver) {
        this.resolver = resolver;
        final String s = resolver.resolveStringValue("我就测试一下 resolver 好不好用：#{1+2}，${os.name}");
        System.out.println(s);

    }
}
